﻿// Apache-2.0 License
// Copyright (c) 2021-2022 朱飞龙
// 电话/微信：18706708563  QQ群：136192142

using Furion.Schedule;
using Furion.TaskQueue;
using Radius.NET.Interface.Kingdee.Service.BasicInfoModule;

namespace Radius.NET.Interface.Job;

//[JobDetail("sync_kingdee_bomlist", Description = "同步配方档案", GroupName = "default", Concurrent = false)]
//[Daily(TriggerId = "trigger_sync_kingdee_bomlist", Description = "同步金蝶资料")]
//[PeriodSeconds(10, TriggerId = "trigger_sync_kingdee_bomlist", Description = "同步配方档案", MaxNumberOfRuns = 1, RunOnStart = true)]
public class SyncKindeeBomListJob
{
    private readonly IServiceProvider _serviceProvider;

    public SyncKindeeBomListJob(IServiceProvider serviceProvider)
    {
        _serviceProvider = serviceProvider;
    }
    public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
    {
        await TaskQueued.EnqueueAsync(async (provider, token) =>
        {
            using var serviceScope = _serviceProvider.CreateScope();
            var bascInfoService = serviceScope.ServiceProvider.GetService<ProductBomService>()!;

            Log.Information("【" + DateTime.Now + "】同步配方档案");

            //同步一周之内的数据
            string date = context.OccurrenceTime.AddDays(-7).ToString("yyyy-MM-dd");

            //同步配方档案
            await bascInfoService.SyncBomList(39, date);
        });

    }
}
